package mapper

// FROM 表名
func (m MapperQuery) From(fromStr string) *MapperQuery {

	if m.fromType == FromTypeT {
		panic("不能同时使用From*和NewQueryWithT")
	}

	if m.fromType > FromTypeT {
		panic("From*不能多次调用")
	}
	m.fromType = 200
	m.fromType200Str = fromStr

	return &m
}

// FROM 子查询
func (m MapperQuery) FromChild(ms *MapperQuery) *MapperQuery {

	if m.fromType == FromTypeT {
		panic("不能同时使用From*和NewQueryWithT")
	}

	if m.fromType > FromTypeT {
		panic("From*不能多次调用")
	}

	m.fromType = 300

	m.childQueries = append(m.childQueries, *ms)
	return &m
}

// FROM Union子查询
func (m MapperQuery) FromUnion(ms ...*MapperQuery) *MapperQuery {

	if m.fromType == FromTypeT {
		panic("不能同时使用From*和NewQueryWithT")
	}
	if m.fromType > FromTypeT {
		panic("From*不能多次调用")
	}
	m.fromType = 400

	for i := range ms {
		m.childQueries = append(m.childQueries, *ms[i])
	}

	return &m
}

// FROM UnionAll子查询
func (m MapperQuery) FromUnionAll(ms ...*MapperQuery) *MapperQuery {

	if m.fromType == FromTypeT {
		panic("不能同时使用From*和NewQueryWithT")
	}
	if m.fromType > FromTypeT {
		panic("From*不能多次调用")
	}
	m.fromType = 500
	for i := range ms {
		m.childQueries = append(m.childQueries, *ms[i])
	}

	return &m
}

// FROM UnionDistinct子查询
func (m MapperQuery) FromUnionDistinct(ms ...*MapperQuery) *MapperQuery {

	if m.fromType == FromTypeT {
		panic("不能同时使用From*和NewQueryWithT")
	}
	if m.fromType > FromTypeT {
		panic("From*不能多次调用")
	}
	m.fromType = 600
	for i := range ms {
		m.childQueries = append(m.childQueries, *ms[i])
	}

	return &m
}
